package com.itheima.reggie.Interceptor;

import com.alibaba.fastjson.JSON;
import com.itheima.reggie.entity.Result;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//继承拦截器
@Component
public class LoginCheckIntercetor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object employee = request.getSession().getAttribute("employee");

        Object user = request.getSession().getAttribute("user");

        if( employee == null && user == null ){
            response.getWriter().print(JSON.toJSON(Result.error("NOTLOGIN")));
            return false;
        }
        return true;
    }

}
